<?php
/**
 * Core_Controller_Action_Helper_FlashMessenger
 * 
 * @author naspeh
 * @version $Id: FlashMessenger.php 658 2008-06-13 14:24:51Z naspeh $
 */
class Core_Controller_Action_Helper_FlashMessenger extends Zend_Controller_Action_Helper_FlashMessenger  
{
    /**
     * Добавляет сообщение
     *
     * @param string $message
     * @param string $type
     * @return Core_Controller_Action_Helper_FlashMessenger
     */
    public function addMessage($body, $type = null)
    {
        if (self::$_messageAdded === false) {
            self::$_session->setExpirationHops(1, null, true);
        }
        if (!is_array(self::$_session->{$this->_namespace})) {
            self::$_session->{$this->_namespace} = array();
        }
        self::$_session->{$this->_namespace}[$body] =  $type;
        return $this;
    }
    /**
     * Strategy pattern: proxy to addMessage()
     *
     * @param string $message
     * @param string $type
     * @return Core_Controller_Action_Helper_FlashMessenger
     */
    public function direct($body, $type = null)
    {
        return $this->addMessage($body, $type);
    }
    /**
     * Добавляет сообщения
     *
     * @param array $messages
     */
    public function addMessages(array $messages)
    {
        foreach ($messages as $body => $type){
            $this->addMessage($body, $type);
        }
    }
    /**
     * Запускается до диспетчеризации
     *
     * @return Core_Controller_Action_Helper_FlashMessenger
     */
    public function preDispatch()
    {
        Core_Message::set($this->getMessages());
        return $this;    
    }
}